package com.hq.fxh.No1_Infromation.Infor.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;
import com.hq.fxh.CustomerView.MyTextView;
import com.hq.fxh.CustomerView.ShareDialogUtils;
import com.hq.fxh.No0_ChengQu.Activity.News_AddAD_DetailActivity;
import com.hq.fxh.No0_ChengQu.Activity.BaseActivity;
import com.hq.fxh.R;
import com.hq.fxh.Utils.ClickUtils;
import com.hq.fxh.Utils.IntentUtils;
import com.hq.fxh.Utils.LogUtils;

import java.io.File;


public class NewsDetailsActivity extends BaseActivity implements View.OnClickListener {

    protected LinearLayout detailBack;
    protected LinearLayout detailMore;
    protected ImageView imageShouChang;
    protected ImageView imageDetailsMore;
    private BridgeWebView newsDetails;
    protected TextView imageNewsDetailsWrite;
    protected LinearLayout imageNewsDetailsComment;
    protected LinearLayout imageNewsDetailsShouChang;
    protected LinearLayout imageNewsDetailsShare;
    protected MyTextView addAd;
    private String newUrl;
    private boolean idShouChang = false;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_news_details;
    }

    @Override
    protected void initView() {
        detailBack = (LinearLayout) findViewById(R.id.detail_Back);
        detailBack.setOnClickListener(NewsDetailsActivity.this);
        detailMore = (LinearLayout) findViewById(R.id.detail_More);
        detailMore.setOnClickListener(NewsDetailsActivity.this);
        newsDetails = (BridgeWebView) findViewById(R.id.webView_NewsDetails);
        //   newsDetails = (WebView) findViewById(R.id.news_details);
        imageNewsDetailsWrite = (TextView) findViewById(R.id.image_NewsDetails_Write);
        imageNewsDetailsWrite.setOnClickListener(NewsDetailsActivity.this);
        imageNewsDetailsComment = (LinearLayout) findViewById(R.id.image_NewsDetails_Comment);
        imageNewsDetailsComment.setOnClickListener(NewsDetailsActivity.this);
        imageNewsDetailsShouChang = (LinearLayout) findViewById(R.id.image_NewsDetails_ShouChang);
        imageNewsDetailsShouChang.setOnClickListener(NewsDetailsActivity.this);
        imageNewsDetailsShare = (LinearLayout) findViewById(R.id.image_NewsDetails_Share);
        imageNewsDetailsShare.setOnClickListener(NewsDetailsActivity.this);
        addAd = (MyTextView) findViewById(R.id.addAd);
        addAd.setOnClickListener(NewsDetailsActivity.this);
        imageShouChang = (ImageView) findViewById(R.id.image_ShouChang);
        imageDetailsMore = (ImageView) findViewById(R.id.image_Details_More);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        newUrl = intent.getStringExtra("url");
        newsDetails.setWebChromeClient(new WebChromeClient());
        WebSettings settings = newsDetails.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptEnabled(true);//支持javascript
        settings.setUseWideViewPort(true);//适配屏幕
        settings.setLoadWithOverviewMode(true);
        settings.setBuiltInZoomControls(true);//支持放大缩小
        settings.setDisplayZoomControls(false);//隐藏放大缩小的按钮
        settings.setDomStorageEnabled(true);//支持Html5标签
        settings.setJavaScriptCanOpenWindowsAutomatically(true);

        newsDetails.loadUrl(newUrl);
        newsDetails.registerHandler("Appinteractive", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                LogUtils.e("指定Handler接收来自web的数据：" + data);
                function.onCallBack("指定Handler收到Web发来的数据，回传数据给你");
            }
        });


        addAd.setMyClick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(NewsDetailsActivity.this, News_AddAD_DetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("NewsUrl", newUrl);
                intent.putExtras(bundle);
                startActivity(intent);

            }
        });

    }

    public void pasterNewsUrl(String url) {
        /** 用户粘贴文章文章操作 */
/*        ArticleServiceImpl.pasterNewsUrl(url, new NetworkSubscriber<CommonRes>() {
            @Override
            public int onSuccess(CommonRes data) {
                super.onSuccess(data);
                if (data != null && data.getCode() == 0) {
                    Bundle bundle = new Bundle();
                    bundle.putString("NewsUrl", pasteURL);
                    IntentUtils.openActivity(getActivity(), News_AddAD_DetailActivity.class, bundle);
                } else {
                    ToastUtils.show(getActivity(), data.getMsg());
                }
                return 0;
            }
        });*/
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.detail_Back) {
            finish();
        } else if (view.getId() == R.id.detail_More) {

        } else if (view.getId() == R.id.image_NewsDetails_Write) {
            ClickUtils.clickComment(this, imageNewsDetailsWrite);

        } else if (view.getId() == R.id.image_NewsDetails_Comment) {

        } else if (view.getId() == R.id.image_NewsDetails_ShouChang) {
            idShouChang = ClickUtils.clickShouChang(this, imageShouChang, idShouChang);

        } else if (view.getId() == R.id.image_NewsDetails_Share) {
            ShareDialogUtils.showShareView(this, imageNewsDetailsShare, new ShareDialogUtils.SharePopCallBack() {
                @Override
                public void Call(AdapterView<?> adapterView, View view, int i, long l) {
                    LogUtils.e(i + "   " + l);

                }
            });

        }
    }

}
